package com.spyz.hdfs_api;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.net.URI;

public class P2_Hdfs_api_put_2 {
    public static void main(String[] args) throws Exception {


        URI uri = new URI("hdfs://master:8020");
        /**
         * 参数优先级
         * 最低到高：
         * hdfs-default.xml => hdfs-site.xml => Configuration
         */

        // 默认副本数为 3
        // hdfs-site.xml设置的副本数为 1
        // 设置文件副本数
        Configuration conf = new Configuration();
        conf.set("dfs.replication","2");

        String user = "root";

        FileSystem fs = FileSystem.get(uri, conf,user);

        fs.copyFromLocalFile(
                false,
                false,
                new Path("./data/word.txt"),
                new Path("/hdfs_api")
        );


        fs.close();
    }
}
